
rm(list = ls()) #清空内存函数
library(RMySQL)
con <- dbConnect(MySQL(),host="192.168.3.139",
                 dbname="niek_160906",user="niek",password="FbWf8AKC")  
dbSendQuery(con,'set names utf8')

city_code<-'bj'
pty<-22
minmum_city<-30   #城市最小样本量设定
minmum_dist<-30   #行政区最小样本量设定

#读取城市列表及季度日期
season_date<-read.csv('yangsj/season_date.csv')
city_list<-read.csv('yangsj/city_list.csv')

#抽取数据
source('R/load_spatial_data.R')

#ha_price与ha_phase数据处理
library(dplyr)
price_sale<-subset(tabln.vec$ha_price,proptype==pty)[,c('ymid','ha_code','saleprice','salebldgarea')]%>%na.omit

#关联季度日期
ps_sale<-merge(price_sale,season_date[,2:3],by='ymid')

#关联POI与info数据
ppi_sale<-merge(ps_sale,ha_info.sp,by='ha_code')

#城市级别模型建立
cat(city_code,'model building...','\n')
myvar_city<-names(ppi_sale) %in% c('ymid','city_code','ha_code','proptype','salecount','name','ha_cl_code','ha_cl_name','dist_code','dist_name','x','y','volume_rate','greening_rate')
sale<-ppi_sale[!myvar_city]

#城市最小样本量设定
tab.date<-table(ppi_sale$season)%>%as.data.frame%>%subset(Freq>=minmum_city)
city_mean<-mean(tab.date$Freq)
city_mean

dbDisconnect(con)
